Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 pkg/crd: fix alias type parsing for struct type alias #1122

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Jan 6, 2025

Fixes #1088.

This was actually breaking all struct type alias I think, not especially when using embedded/inline struct.

I tested that both should pass:

$ GODEBUG=gotypesalias=1 go test ./pkg/crd
ok      sigs.k8s.io/controller-tools/pkg/crd    2.888s
$ GODEBUG=gotypesalias=0 go test ./pkg/crd
ok      sigs.k8s.io/controller-tools/pkg/crd    2.928s

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 6, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 6, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @mtardy. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 6, 2025
@mtardy
Copy link
Member Author

mtardy commented Jan 6, 2025

/cc sbueringer @tsaarni

@k8s-ci-robot
Copy link
Contributor

@mtardy: GitHub didn't allow me to request PR reviews from the following users: tsaarni.

Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc sbueringer tsaarni

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

mtardy and others added 2 commits January 6, 2025 12:14
Using Underlying() was working for basic types but was resolving "too
far" for more complex type, as for the structure. I.e. instead of
retrieving the new type for aliased, it actually retrieved the
underyling (who could have guessed) actual type.

For example, for a string alias, we have:
- Alias type info:           testdata.kubebuilder.io/cronjob.StringAlias
- Rhs from the alias def:    string
- Underlying from the alias: string

But for a struct alias, we have:
- Alias type info:           testdata.kubebuilder.io/cronjob.InlineAlias
- Rhs from the alias def:    testdata.kubebuilder.io/cronjob.EmbeddedStruct
- Underlying from the alias: struct{FromEmbedded string "json:\"fromEmbedded,omitempty\""}

I also imagine that we don't handle nested alias, but this is for
another patch.

Signed-off-by: Mahe Tardy <[email protected]>
User tsaarni bumped into a panic when using embedded/inline field with a
type alias and that Alias types are enabled in Go. They thankfully
included a reproducer that is shipped in this patch from the issue
kubernetes-sigs#1088.

Co-authored-by: Tero Saarni <[email protected]>
Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/embedded-alias branch from 470bfea to cf0446d Compare January 6, 2025 11:14
@mtardy
Copy link
Member Author

mtardy commented Jan 6, 2025

Hi @mtardy. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Btw @sbueringer I'm a member of @kubernetes, do you know how hard it would be to be added to @kubernetes-sigs?

@mtardy
Copy link
Member Author

mtardy commented Jan 6, 2025

Btw @sbueringer I'm a member of https://github.com/kubernetes, do you know how hard it would be to be added to https://github.com/kubernetes-sigs?

Turns out it was fairly easy, kubernetes/org#5326.

/ok-to-test

@k8s-ci-robot
Copy link
Contributor

@mtardy: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

Btw @sbueringer I'm a member of https://github.com/kubernetes, do you know how hard it would be to be added to https://github.com/kubernetes-sigs?

Turns out it was fairly easy, kubernetes/org#5326.

/ok-to-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@mtardy
Copy link
Member Author

mtardy commented Jan 6, 2025

well, I was a bit too early

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 6, 2025
@cbandy
Copy link
Contributor

cbandy commented Jan 6, 2025

Related, maybe: #1119

@sbueringer
Copy link
Member

Thank you!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: c9f9e411001b9dfbcea9526324c37e3dcefa8298

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mtardy, sbueringer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 10, 2025
@k8s-ci-robot k8s-ci-robot merged commit 9814fc3 into kubernetes-sigs:main Jan 10, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Embedded / inline type aliases trigger panic
4 participants